/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { ApiResult } from './ApiResult';

type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;
type RequestInterceptor = (options: ApiRequestOptions) => ApiRequestOptions | Promise<ApiRequestOptions>;
type ResponseInterceptor = (result: ApiResult) => ApiResult | Promise<ApiResult>;

type Config = {
    BASE: string;
    VERSION: string;
    WITH_CREDENTIALS: boolean;
    TOKEN?: string | Resolver<string>;
    USERNAME?: string | Resolver<string>;
    PASSWORD?: string | Resolver<string>;
    HEADERS?: Headers | Resolver<Headers>;
    ReqInterceptors: RequestInterceptor[];
    RspInterceptors: ResponseInterceptor[];
    TIMEOUT: number;
}

export const OpenAPI: Config = {
    BASE: '',
    VERSION: '0.0.1',
    WITH_CREDENTIALS: false,
    TOKEN: undefined,
    USERNAME: undefined,
    PASSWORD: undefined,
    HEADERS: undefined,
    ReqInterceptors: [],
    RspInterceptors: [],
    TIMEOUT: 30 * 1000,
};

export function AddRequestInterceptor(r: RequestInterceptor) {
    OpenAPI.ReqInterceptors.push(r);
}

export function AddResponseInterceptor(r: ResponseInterceptor) {
    OpenAPI.RspInterceptors.push(r);
}

export function SetServiceApiTimeout(timeout: number) {
    OpenAPI.TIMEOUT = timeout * 1000;
}